import java.util.*;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 26727
 * Date: 2025-07-10
 * Time: 16:54
 */
public class Test47 {

    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int val) {
            this.val = val;
        }

        TreeNode() {

        }

        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }

    static TreeNode head = new TreeNode();

    public static void flatten(TreeNode root) {
        if(root == null) {
            return;
        }
        dfs(root);
    }

    public static void dfs(TreeNode root) {
        TreeNode tmp1 = new TreeNode();
        TreeNode tmp2 = new TreeNode();
        tmp1 = root.left;
        tmp2 = root.right;

        head.right = root;
        head.left = null;
        head = head.right;

        if(tmp1 != null) {
            dfs(tmp1);
        }
        if(tmp2 != null) {
            dfs(tmp2);
        }
    }

    public static TreeNode build(String s) {
        String input = s.replace("[", "").replace("]", "");
        String[] parts = input.split(",");
        Integer[] num = new Integer[parts.length];

        for (int i = 0; i < parts.length; i++) {
            if (!parts[i].equals("null")) {
                num[i] = Integer.parseInt(parts[i]);
            } else {
                num[i] = null;
            }
        }

        // 重点
        if (num.length == 0 || num[0] == null) {
            return null;
        }

        TreeNode root = new TreeNode(num[0]);
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        int index = 1;

        while (!q.isEmpty() && index < num.length) {
            TreeNode cur = q.poll();

            if (index < num.length && num[index] != null) {
                cur.left = new TreeNode(num[index]);
                q.offer(cur.left);
            }
            index++;

            if (index < num.length && num[index] != null) {
                cur.right = new TreeNode(num[index]);
                q.offer(cur.right);
            }
            index++;
        }

        return root;
    }

    public static List<Integer> levelT(TreeNode root) {
        List<Integer> ret = new ArrayList<>();
        if (root == null) {
            return ret;
        }
        Queue<TreeNode> q = new LinkedList<>();
        q.offer(root);
        while (!q.isEmpty()) {
            int size = q.size();
            while (size > 0) {
                TreeNode node = q.poll();
                if (node != null) {
                    ret.add(node.val);
                    q.offer(node.left);
                    q.offer(node.right);
                } else {
                    ret.add(null);
                }
                size--;
            }
        }
        //移除末尾的null
        while (ret.size() > 0 && ret.get(ret.size() - 1) == null) {
            ret.remove(ret.size() - 1);
        }
        return ret;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        TreeNode root = build(s);
        flatten(root);
        List<Integer> ret = levelT(root);
        System.out.println(ret);
    }
}
